﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.IO;
namespace Wys.DataForm.CSharp
{
    public partial class RestoreForm : Wys.Control.Vb.AutoAdjustFrom
    {
        #region 构造函数
        public RestoreForm()
        {
            InitializeComponent();
        }
        #endregion

        #region 查找数据库文件
        public String GetDataPathFolder(String strPath)
        {
            String strRt = "";
            strPath = System.IO.Path.Combine(strPath, "SQLITEDATA");
            if (!System.IO.Directory.Exists(strPath))
            {
                goto FUNCTION_FAILED;
            }
            System.IO.DirectoryInfo dif = new System.IO.DirectoryInfo(strPath);

            foreach (System.IO.FileInfo fi in dif.GetFiles())
            {
                if (fi.Name.ToUpper().StartsWith("XSC") && fi.Extension.ToUpper() == ".DB")
                {
                    strRt = fi.FullName;
                    goto FUNCTION_SUCCESSED;
                }
            }
        FUNCTION_SUCCESSED:
            return strRt;
        FUNCTION_FAILED:
            return "";
        }
        #endregion

        #region 调用WINRAR压缩 A-2009-09-13
        /// <summary>
        /// 调用WINRAR解压 
        /// </summary>
        /// <param name="strSource">要解压的文件</param>
        /// <param name="strTarget">解压后的文件</param>
        /// <returns></returns>
        /// 0 是失败
        /// 1 是成功
        public int UnRar(String strSource, String strTarget)
        {
            int iRusult = 0;
            try
            {
                System.Diagnostics.Process Process1 = new System.Diagnostics.Process();
                Process1.StartInfo.FileName = "Winrar.exe";
                Process1.StartInfo.CreateNoWindow = true;
                Process1.StartInfo.Arguments = " X   -ibck \"" + strSource + "\"   *.*  \"" + strTarget + "\\\"";
                Process1.Start();
                Process1.WaitForExit();
                if (Process1.HasExited)
                {
                    int iExitCode = Process1.ExitCode;
                    if (iExitCode == 0)
                    {
                        //正常完成
                        iRusult = 1;
                    }
                    else
                    {
                        //有错
                        iRusult = 0;
                    }
                }
                Process1.Close();
                return iRusult;
            }
            catch (Exception me)
            {
                //SaveException(me);//D-2009-10-11
                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());//A-2009-10-11 
                iRusult = 0;
                return iRusult;
            }
        }
        #endregion

        #region 选择文件夹
        private void btnCompressionSelect_Click(object sender, EventArgs e)
        {

            this.openFileDialog1.Filter = "压缩文件|*.rar";
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                this.txtCompressionPath.Text = this.openFileDialog1.FileName;
                String strName = System.IO.Path.GetFileName(txtCompressionPath.Text);
                this.txtCompressionPath.Text = this.openFileDialog1.FileName;
            }
        }
        #endregion

        #region 查找更新图片文件
        private System.IO.FileInfo[] GetImages(String strPath)
        {
            strPath = System.IO.Path.Combine(strPath, "Images");
            if (!System.IO.Directory.Exists(strPath))
            {
                goto FUNCTION_FAILED;
            }
            System.IO.DirectoryInfo dif = new System.IO.DirectoryInfo(strPath);
            return dif.GetFiles();
        FUNCTION_FAILED:
            return null;
        }
        #endregion

        #region 查找附件文件
        private System.IO.FileInfo[] GetAtts(String strPath)
        {
            strPath = System.IO.Path.Combine(strPath, "UpLoad");
            if (!System.IO.Directory.Exists(strPath))
            {
                goto FUNCTION_FAILED;
            }
            System.IO.DirectoryInfo dif = new System.IO.DirectoryInfo(strPath);
            return dif.GetFiles();
        FUNCTION_FAILED:
            return null;
        }
        #endregion

        #region 查找小软件件
        private System.IO.DirectoryInfo[] GetSoftWare(String strPath)
        {
            strPath = System.IO.Path.Combine(strPath, "SoftWare");
            if (!System.IO.Directory.Exists(strPath))
            {
                goto FUNCTION_FAILED;
            }
            System.IO.DirectoryInfo dif = new System.IO.DirectoryInfo(strPath);
            return dif.GetDirectories();
        FUNCTION_FAILED:
            return null;
        }
        #endregion

        #region 还原按钮事件

        private void StateChange(object sender, EventArgs e)
        {
            if ((!this.chkGroup3Att.Checked) && (!this.chkGroup3Database.Checked) && (!this.chkGroup3Image.Checked) && (!chkSoftWare.Checked))
            {
                this.btnCompressionRestore.Enabled = false;
                this.btnCompressionSelect.Enabled = false;
            }
            else
            {
                this.btnCompressionRestore.Enabled = true;
                this.btnCompressionSelect.Enabled = true;
            }
        }
        private void btnCompressionRestore_Click(object sender, EventArgs e)
        {           
            this.lstStatus.Items.Clear();
            if (txtCompressionPath.Text.Trim() == string.Empty)
            {
                return;
            }
            if (!System.IO.File.Exists(txtCompressionPath.Text.Trim()))
            {
                txtCompressionPath.Text = "";
                return;
            }
            if (chkAll.Checked)
            {
                if (ShowMessageResult("整体还原会覆盖掉数据库，请慎用，覆盖吗？") != DialogResult.Yes)
                {
                    return;
                }
            }
            String strPath = this.txtCompressionPath.Text;
            System.IO.FileInfo fin = new System.IO.FileInfo(strPath);

            String strPathChild = System.IO.Path.Combine(fin.Directory.FullName, fin.Name.Substring(0, fin.Name.Length - fin.Extension.Length));

            try
            {
                System.IO.Directory.Delete(strPathChild, true);
            }
            catch (DirectoryNotFoundException dfe)
            {
                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, dfe, MethodBase.GetCurrentMethod().GetType());
            }
            catch (Exception me)
            {
                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                ShowMessageBox("这个" + strPathChild + "文件夹 必须关闭,或直接删除");
                return;
            }
            lstStatus.Items.Add("开始解压文件:" + strPath + "......");

            String txtPath = "";

            //解压文件夹
            if (UnRar(strPath, strPathChild) == 1)
            {
                lstStatus.Items.Add("解压文件成功");
            }
            else
            {
                lstStatus.Items.Add("解压文件失败");
            }

            //整体还原
            if (chkAll.Checked)
            {
                //查找数据库文件      
                if (chkGroup3Database.Checked)
                {
                    //查找数据库文件
                    txtPath = GetDataPathFolder(strPathChild);
                    if (!System.IO.File.Exists(txtPath))
                    {
                        return;
                    }

                    lstStatus.Items.Add("开始还原数据库");

                    try
                    {
                        String strPath1 = Wys.Db.Vb.CTable.GetDatabasePath();

                        lstStatus.Items.Add("开始删除旧数据库文件......");
                        ct.CloseAllDb();
                        GC.Collect();

                        while (true)
                        {
                            try
                            {
                                System.IO.File.Delete(strPath1);
                                lstStatus.Items.Add("删除旧数据库文件成功");
                                break;
                            }
                            catch (Exception)
                            {
                                lstStatus.Items.Add("删除旧数据库文件失败");
                            }
                            Application.DoEvents();
                        }

                        System.IO.FileInfo fin1 = new System.IO.FileInfo(txtPath);
                        lstStatus.Items.Add("开始拷贝新数据库文件......");

                        fin1.CopyTo(strPath1);

                        lstStatus.Items.Add("拷贝新数据库文件成功");

                    }
                    catch (Exception)
                    {
                        lstStatus.Items.Add("还原数据库文件失败,请手动还原");
                    }
                }
            }
            else //差异还原
            {
                //data source=D:\WYSHibernate\Wys.Data\Wys.Data\Data\XSC.db

                //查找数据库文件
                txtPath = GetDataPathFolder(strPathChild);
                if (!System.IO.File.Exists(txtPath))
                {
                    return;
                }
                using (System.Data.SQLite.SQLiteConnection sc = new System.Data.SQLite.SQLiteConnection("data source=" + txtPath))
                {
                    try
                    {
                        sc.Open();

                        ADODB.Recordset rsVersion = ct.GetTable("select * from XSCVersion");
                        if (!rsVersion.EOF)
                        {
                            this.txtVersion.Text = DateTime.Parse(rsVersion.Fields["DateTime"].Value.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                            rsVersion.Close();
                        }                     

                        #region XSCENLISHWORD 英语单词表  
                        String strSql = "select * from XSCENLISHWORD where  datetime([OPTIME])>='" + txtVersion.Text + "'";
                        System.Data.SQLite.SQLiteDataAdapter sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable dtEnglish = new DataTable();
                        sda.Fill(dtEnglish);
                        dtEnglish.TableName = "XSCENLISHWORD";
                        //TEST
                        List<String> keys = new List<String>();
                        List<ADODB.Parameter> insertParam = new List<ADODB.Parameter>();
                        List<ADODB.Parameter> UpdateParam = new List<ADODB.Parameter>();
                        List<ADODB.Parameter> SelectParam = new List<ADODB.Parameter>();
                        ADODB.Command cmdTemp = new ADODB.Command();
                        insertParam.Add(cmdTemp.CreateParameter("ID",
                                       ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput,
                                       10,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("WORD",
                                       ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput,
                                       100,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("CHINESEWORD",
                                       ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput,
                                       100,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("MEMO",
                                       ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput,
                                       1000,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("OPTIME",
                                       ADODB.DataTypeEnum.adDBTimeStamp, ADODB.ParameterDirectionEnum.adParamInput,
                                       100,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("AddTime",
                                       ADODB.DataTypeEnum.adDBTimeStamp, ADODB.ParameterDirectionEnum.adParamInput,
                                       100,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("OptUser",
                                       ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput,
                                       50,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("USERNAME",
                                       ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput,
                                       50,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("Count",
                                       ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput,
                                       10,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("WordType",
                                       ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput,
                                       10,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("SyombalEnglish",
                                       ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput,
                                       100,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("SyombalAmerican",
                                       ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput,
                                       100,
                                       System.Reflection.Missing.Value));

                        SelectParam.Add(cmdTemp.CreateParameter("WORD1",
                                       ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput,
                                       100,
                                       System.Reflection.Missing.Value));

                        UpdateParam.AddRange(insertParam);
                        UpdateParam.AddRange(SelectParam);

                        keys.Add("WORD");
                        更新表(dtEnglish, keys, insertParam.ToArray(), UpdateParam.ToArray(), SelectParam.ToArray());
                        #endregion

                        ADODB.Recordset rs = null;
                        //XSCENLISHWORD 英语单词表
                        
                        #region XSCWORD 日语单词表
                        //XSCWORD 日语单词表
                        strSql = "select * from XSCWORD where datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable dtXSCWORD = new DataTable();
                        sda.Fill(dtXSCWORD);
                        foreach (DataRow dr in dtXSCWORD.Rows)
                        {
                            try
                            {
                                rs = ct.GetUpdateRs("SELECT * FROM XSCWORD   WHERE JAPANWORD='" + dr["JAPANWORD"].ToString().ToUpper() + "'");
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["ID"].Value = dr["ID"];
                                    rs.Fields["JAPANWORD"].Value = dr["JAPANWORD"];
                                    rs.Fields["JAPANPLANT"].Value = dr["JAPANPLANT"];
                                    rs.Fields["CHINESEPLANT"].Value = dr["CHINESEPLANT"];
                                    rs.Fields["JAPANJUZHI"].Value = dr["JAPANJUZHI"];
                                    rs.Fields["CHINAJUZHI"].Value = dr["CHINAJUZHI"];
                                    rs.Fields["OPTIME"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["AddTime"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["OptUser"].Value = this.strName;
                                    rs.Fields["USERNAME"].Value = this.strName;
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("日语单词 添加了" + dr["JAPANWORD"].ToString());
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                else
                                {
                                    rs.Fields["JAPANWORD"].Value = dr["JAPANWORD"];
                                    rs.Fields["JAPANPLANT"].Value = dr["JAPANPLANT"];
                                    rs.Fields["CHINESEPLANT"].Value = dr["CHINESEPLANT"];
                                    rs.Fields["JAPANJUZHI"].Value = dr["JAPANJUZHI"];
                                    rs.Fields["CHINAJUZHI"].Value = dr["CHINAJUZHI"];
                                    rs.Fields["OPTIME"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["OptUser"].Value = this.strName;
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("日语单词 更新了" + dr["JAPANWORD"].ToString());
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add(dr["WORD"].ToString() + ":" + "单词插入失败");
                            }

                        }
                        //XSCWORD 日语单词表 
                        #endregion                                                                 

                        //XSCCODE 
                        strSql = "select * from XSCCODE where  datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable dtSmileBs = new DataTable();
                        sda.Fill(dtSmileBs);
                        foreach (DataRow dr in dtSmileBs.Rows)
                        {
                            try
                            {
                                rs = ct.GetUpdateRs("SELECT ID,TITLE,CODE,CODEPLANT,type,AttachType,AttachFileName,USERNAME,OPTIME,OptUser,AddTime,FormType FROM XSCCODE where ID='" + dr["ID"] + "'");
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["FormType"].Value = dr["FormType"];
                                    rs.Fields["ID"].Value = dr["ID"];
                                    rs.Fields["TITLE"].Value = dr["TITLE"];
                                    //rs.Fields["CODE"].Value = dr["CODE"];
                                    rs.Fields["CODEPLANT"].Value = dr["CODEPLANT"];
                                    rs.Fields["AttachType"].Value = dr["AttachType"];
                                    rs.Fields["AttachFileName"].Value = dr["AttachFileName"];
                                    rs.Fields["type"].Value = dr["type"];
                                    rs.Fields["OPTIME"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["AddTime"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["OptUser"].Value = this.strName;
                                    rs.Fields["USERNAME"].Value = this.strName;
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Close();
                                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
                                    rs = null;
                                    rs = ct.GetUpdateRs("SELECT ID,TITLE,CODE,CODEPLANT,type,AttachType,AttachFileName,USERNAME,OPTIME,OptUser,AddTime,FormType FROM XSCCODE where ID='" + dr["ID"] + "'");
                                    rs.Fields["CODE"].Value = dr["CODE"];
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("代码 增加了一条 标题为 " + ":" + dr["TITLE"].ToString() + "的记录");
                                    rs.Close();
                                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
                                    rs = null;
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                else
                                {
                                    rs.Fields["FormType"].Value = dr["FormType"];
                                    rs.Fields["TITLE"].Value = dr["TITLE"];
                                    //rs.Fields["CODE"].Value = dr["CODE"];
                                    rs.Fields["CODEPLANT"].Value = dr["CODEPLANT"];
                                    rs.Fields["AttachType"].Value = dr["AttachType"];
                                    rs.Fields["AttachFileName"].Value = dr["AttachFileName"];
                                    rs.Fields["type"].Value = dr["type"];
                                    rs.Fields["OPTIME"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["OptUser"].Value = this.strName;
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Close();
                                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
                                    rs = null;
                                    rs = ct.GetUpdateRs("SELECT ID,TITLE,CODE,CODEPLANT,type,AttachType,AttachFileName,USERNAME,OPTIME,OptUser,AddTime,FormType FROM XSCCODE where ID='" + dr["ID"] + "'");
                                    rs.Fields["CODE"].Value = dr["CODE"];
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("代码 更新了一条 标题为 " + ":" + dr["TITLE"].ToString() + "的记录");
                                    rs.Close();
                                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
                                    rs = null;
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                               
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("代码 更新 标题为 " + ":" + dr["TITLE"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面

                            }
                            //XSCSMILEIE 项目学习表                           
                        }                      

                        //XscBugType
                        strSql = "select * from XscBugType where  datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable dtXscBugType = new DataTable();
                        sda.Fill(dtXscBugType);
                        foreach (DataRow dr in dtXscBugType.Rows)
                        {
                            try
                            {
                                rs = ct.GetUpdateRs("SELECT * FROM XscBugType where ID='" + dr["ID"] + "'");
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["ID"].Value = dr["ID"];
                                    rs.Fields["Name"].Value = dr["Name"];
                                    rs.Fields["ParentID"].Value = dr["ParentID"];                                   
                                    rs.Fields["type"].Value = dr["type"];
                                    rs.Fields["OPTIME"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["AddTime"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["OptUser"].Value = this.strName;
                                    rs.Fields["USERNAME"].Value = this.strName;
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("类型表 增加了一条 名称为 " + ":" + dr["Name"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                else
                                {
                                    rs.Fields["Name"].Value = dr["Name"];
                                    rs.Fields["ParentID"].Value = dr["ParentID"];
                                    rs.Fields["type"].Value = dr["type"];
                                    rs.Fields["OPTIME"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["OptUser"].Value = this.strName;
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("类型表 更新了一条 名称为 " + ":" + dr["Name"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("类型 更新 标题为 " + ":" + dr["Name"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //XscBugType

                        //XSCFEEL BUG表
                        strSql = "select * from XSCFEEL where  datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable dtXSCFEEL = new DataTable();
                        sda.Fill(dtXSCFEEL);
                        foreach (DataRow dr in dtXSCFEEL.Rows)
                        {
                            try
                            {
                                rs = ct.GetUpdateRs("SELECT * FROM XSCFEEL where date([DATE])='" + DateTime.Parse(dr["DATE"].ToString()).ToString("yyyy-MM-dd") + "' and USERNAME='" + strName + "'");
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);                                   
                                    rs.Fields["DATE"].Value = dr["DATE"];
                                    rs.Fields["PlANT"].Value = dr["PlANT"];
                                    rs.Fields["COMPLETEPLANT"].Value = dr["COMPLETEPLANT"];
                                    rs.Fields["FEEL"].Value = dr["FEEL"];
                                    rs.Fields["FILENAME"].Value = dr["FILENAME"];
                                    rs.Fields["FILE"].Value = dr["FILE"];
                                    rs.Fields["AttachFileName"].Value = dr["AttachFileName"];
                                    rs.Fields["AttachType"].Value = dr["AttachType"];
                                    rs.Fields["OPTIME"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["AddTime"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["OptUser"].Value = this.strName;
                                    rs.Fields["USERNAME"].Value = this.strName;
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("日志感谢 增加了一条 日期为 " + ":" + dr["DATE"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                else
                                {                                 
                                    rs.Fields["PlANT"].Value = dr["PlANT"];
                                    rs.Fields["COMPLETEPLANT"].Value = dr["COMPLETEPLANT"];
                                    rs.Fields["FEEL"].Value = dr["FEEL"];
                                    rs.Fields["FILENAME"].Value = dr["FILENAME"];
                                    rs.Fields["FILE"].Value = dr["FILE"];
                                    rs.Fields["AttachFileName"].Value = dr["AttachFileName"];
                                    rs.Fields["AttachType"].Value = dr["AttachType"];
                                    rs.Fields["OPTIME"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["OptUser"].Value = this.strName;
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("日志感谢 更新了一条 日期为 " + ":" + dr["DATE"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("日志感谢 更新 标题为 " + ":" + dr["DATE"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //XSCBUG BUG表

                        //XscSoftWareType
                        strSql = "select * from XscSoftWareType where datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable dtXscSoftWareType = new DataTable();
                        sda.Fill(dtXscSoftWareType);
                        foreach (DataRow dr in dtXscSoftWareType.Rows)
                        {
                            try
                            {
                                rs = ct.GetUpdateRs("SELECT * FROM XscSoftWareType where ID='" + dr["ID"] + "'");
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["ID"].Value = dr["ID"];
                                    rs.Fields["Name"].Value = dr["Name"];
                                    rs.Fields["ParentID"].Value = dr["ParentID"];
                                    rs.Fields["FolderPath"].Value = dr["FolderPath"];
                                    rs.Fields["OPTIME"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["AddTime"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["OptUser"].Value = this.strName;
                                    rs.Fields["USERNAME"].Value = this.strName;
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("软件类型表 增加了一条 名称为 " + ":" + dr["Name"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                else
                                {
                                    rs.Fields["Name"].Value = dr["Name"];
                                    rs.Fields["ParentID"].Value = dr["ParentID"];                                   
                                    rs.Fields["FolderPath"].Value = dr["FolderPath"];
                                    rs.Fields["OPTIME"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["OptUser"].Value = this.strName;
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("软件类型表 更新了一条 名称为 " + ":" + dr["Name"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("软件类型表 更新 标题为 " + ":" + dr["Name"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //XscSoftWareType

                        //XscSoftWare
                        strSql = "select * from XscSoftWare where datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable dtXscSoftWare = new DataTable();
                        sda.Fill(dtXscSoftWare);
                        foreach (DataRow dr in dtXscSoftWare.Rows)
                        {
                            try
                            {
                                rs = ct.GetUpdateRs("SELECT * FROM XscSoftWare where ID='" + dr["ID"] + "'");
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["ID"].Value = dr["ID"];
                                    rs.Fields["Title"].Value = dr["Title"];
                                    rs.Fields["FileName"].Value = dr["FileName"];
                                    rs.Fields["SoftWare"].Value = dr["SoftWare"];
                                    rs.Fields["Memo"].Value = dr["Memo"];
                                    rs.Fields["IsSingleFile"].Value = dr["IsSingleFile"];
                                    rs.Fields["OPTIME"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["AddTime"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["OptUser"].Value = this.strName;
                                    rs.Fields["USERNAME"].Value = this.strName;
                                    rs.Fields["LastOpenTime"].Value = DateTime.Now.ToString();
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("软件表 增加了一条 名称为 " + ":" + dr["FileName"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                else
                                {
                                    rs.Fields["Title"].Value = dr["Title"];
                                    rs.Fields["FileName"].Value = dr["FileName"];
                                    rs.Fields["SoftWare"].Value = dr["SoftWare"];
                                    rs.Fields["Memo"].Value = dr["Memo"];
                                    rs.Fields["IsSingleFile"].Value = dr["IsSingleFile"];
                                    rs.Fields["OPTIME"].Value = DateTime.Now.ToString();
                                    rs.Fields["LastOpenTime"].Value = DateTime.Now.ToString();
                                    rs.Fields["OptUser"].Value = this.strName;
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("软件表 更新了一条 名称为 " + ":" + dr["FileName"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("软件表 更新 标题为 " + ":" + dr["FileName"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //XscSoftWare

                        //XscWebSite
                        strSql = "select * from XscWebSite where  datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable dtXscWebSite = new DataTable();
                        sda.Fill(dtXscWebSite);
                        foreach (DataRow dr in dtXscWebSite.Rows)
                        {
                            try
                            {
                                rs = ct.GetUpdateRs("SELECT * FROM XscWebSite where ID='" + dr["ID"] + "'");
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["ID"].Value = dr["ID"];
                                    rs.Fields["Title"].Value = dr["Title"];
                                    rs.Fields["WebSiteUrl"].Value = dr["WebSiteUrl"];
                                    rs.Fields["WebSiteTypeName"].Value = dr["WebSiteTypeName"];
                                    rs.Fields["Memo"].Value = dr["Memo"];
                                    rs.Fields["type"].Value = dr["type"];
                                    rs.Fields["OPTIME"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["AddTime"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["OptUser"].Value = this.strName;
                                    rs.Fields["USERNAME"].Value = this.strName;
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("网址表 增加了一条 名称为 " + ":" + dr["Title"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                else
                                {
                                    rs.Fields["Title"].Value = dr["Title"];
                                    rs.Fields["WebSiteUrl"].Value = dr["WebSiteUrl"];
                                    rs.Fields["WebSiteTypeName"].Value = dr["WebSiteTypeName"];
                                    rs.Fields["Memo"].Value = dr["Memo"];
                                    rs.Fields["type"].Value = dr["type"];
                                    rs.Fields["OPTIME"].Value = DateTime.Now.ToString(); ;
                                    rs.Fields["OptUser"].Value = this.strName;
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("网址表 更新了一条 名称为 " + ":" + dr["Title"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("网址表 更新 标题为 " + ":" + dr["Title"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //XscWebSite  

                        //DeleteImageUpdate
                        strSql = "select * from DeleteImageUpdate where  datetime([UptTime])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable DeleteImageUpdate = new DataTable();
                        sda.Fill(DeleteImageUpdate);
                        foreach (DataRow dr in DeleteImageUpdate.Rows)
                        {
                            try
                            {
                                rs = ct.GetUpdateRs("SELECT * FROM DeleteImageUpdate where FileName='" + dr["FileName"] + "'");
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["FileName"].Value = dr["FileName"];
                                    rs.Fields["UserName"].Value = this.strName;
                                    rs.Fields["UptTime"].Value = DateTime.Now.ToString();                                 
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("删除图像表 增加了一条 图片为 " + ":" + dr["FileName"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                else
                                {
                                    //rs.Fields["FileName"].Value = dr["FileName"];
                                    //rs.Fields["UserName"].Value = this.strName;
                                    //rs.Fields["UptTime"].Value = DateTime.Now.ToString();
                                    //rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    //lstStatus.Items.Add("删除图像表 更新了一条 图片为 " + ":" + dr["FileName"].ToString() + "的记录");
                                    //System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("删除图像表 更新 图片为 " + ":" + dr["FileName"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //DeleteImageUpdate  

                        //DeleteTable
                        strSql = "select * from DeleteTable where  datetime([UptTime])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable DeleteTable = new DataTable();
                        sda.Fill(DeleteTable);
                        foreach (DataRow dr in DeleteTable.Rows)
                        {
                            try
                            {
                                String strSqldtXscWebSite = "SELECT * FROM DeleteTable";
                                strSqldtXscWebSite += " where ";
                                strSqldtXscWebSite += "  TableName='" + dr["TableName"] + "'";
                                strSqldtXscWebSite += "  AND Key1='" + dr["Key1"] + "'";
                                strSqldtXscWebSite += "  AND (Key2='" + dr["Key2"] + "' OR key2 is null)";
                                strSqldtXscWebSite += "  AND (Key3='" + dr["Key3"] + "' OR key3 is null)";
                                strSqldtXscWebSite += "  AND value1='" + dr["Value1"] + "'";
                                strSqldtXscWebSite += "  AND (value2='" + dr["Value2"] + "' OR value2 is null)";
                                strSqldtXscWebSite += "  AND (value3='" + dr["Value3"] + "' OR value3 is null)";
                                rs = ct.GetUpdateRs(strSqldtXscWebSite);
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    if (dr["value1"] != DBNull.Value)
                                    {
                                        rs.Fields["value1"].Value = dr["value1"];
                                    }
                                    else
                                    {
                                        rs.Fields["value1"].Value = "";
                                    }

                                    if (dr["value2"] != DBNull.Value)
                                    {
                                        rs.Fields["value2"].Value = dr["value2"];
                                    }
                                    else
                                    {
                                        rs.Fields["value2"].Value = "";
                                    }

                                    if (dr["value3"] != DBNull.Value)
                                    {
                                        rs.Fields["value3"].Value = dr["value3"];
                                    }
                                    else
                                    {
                                        rs.Fields["value3"].Value = "";
                                    }

                                    if (dr["Key1"] != DBNull.Value)
                                    {
                                        rs.Fields["Key1"].Value = dr["Key1"];
                                    }
                                    else
                                    {
                                        rs.Fields["Key1"].Value = "";
                                    }

                                    if (dr["Key2"] != DBNull.Value)
                                    {
                                        rs.Fields["Key2"].Value = dr["Key2"];
                                    }
                                    else
                                    {
                                        rs.Fields["Key2"].Value = "";
                                    }

                                    if (dr["Key3"] != DBNull.Value)
                                    {
                                        rs.Fields["Key3"].Value = dr["Key3"];
                                    }
                                    else
                                    {
                                        rs.Fields["Key3"].Value = "";
                                    }
                                    rs.Fields["TableName"].Value = dr["TableName"];
                                    rs.Fields["UptTime"].Value = DateTime.Now.ToString();
                                    rs.Fields["UserName"].Value = this.strName;
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    //rs.UpdateBatch(ADODB.AffectEnum.adAffectCurrent);
                                    lstStatus.Items.Add("删除表 增加了一条 表名为 " + ":" + dr["TableName"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                //else
                                //{
                                //    rs.Fields["Key1"].Value = dr["Key1"];
                                //    rs.Fields["Key2"].Value = dr["Key2"];
                                //    rs.Fields["Key3"].Value = dr["Key3"];
                                //    rs.Fields["value1"].Value = dr["value1"];
                                //    rs.Fields["value2"].Value = dr["value2"];
                                //    rs.Fields["value3"].Value = dr["value3"];
                                //    rs.Fields["TableName"].Value = dr["TableName"];
                                //    rs.Fields["UptTime"].Value = DateTime.Now.ToString();
                                //    rs.Fields["UserName"].Value = this.strName;
                                //    //rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                //    rs.UpdateBatch(ADODB.AffectEnum.adAffectCurrent);
                                //    lstStatus.Items.Add("删除表 更新了一条 表名为 " + ":" + dr["TableName"].ToString() + "的记录");
                                //    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                //}
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("删除表 更新 表名为 " + ":" + dr["TableName"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //DeleteTable 
 
                        //PrintLog
                        strSql = "select * from PrintLog where  datetime([DateTime])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable PrintLog = new DataTable();
                        sda.Fill(PrintLog);
                        foreach (DataRow dr in PrintLog.Rows)
                        {
                            try
                            {
                                String strSqldtXscWebSite = "SELECT * FROM PrintLog";
                                strSqldtXscWebSite += " where ";
                                strSqldtXscWebSite += "  ID='" + dr["ID"] + "'";                             
                                rs = ct.GetUpdateRs(strSqldtXscWebSite);
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["ID"].Value = dr["ID"];
                                    rs.Fields["type"].Value = dr["type"];
                                    rs.Fields["DateTime"].Value = dr["DateTime"];
                                    rs.Fields["KEYS"].Value = dr["KEYS"];                                                                                        rs.UpdateBatch(ADODB.AffectEnum.adAffectCurrent);
                                    lstStatus.Items.Add("打印日志表 增加了一条 日期为 " + ":" + dr["DateTime"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                else
                                {                                   
                                    rs.Fields["type"].Value = dr["type"];
                                    rs.Fields["DateTime"].Value = dr["DateTime"];
                                    rs.Fields["KEYS"].Value = dr["KEYS"]; 
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    lstStatus.Items.Add("打印日志表 更新了一条 日期为 " + ":" + dr["DateTime"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("打印日志表 更新 日期为 " + ":" + dr["DateTime"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //PrintLog

                        //MEMO
                        strSql = "select * from MEMO where  datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable MEMO = new DataTable();
                        sda.Fill(MEMO);
                        foreach (DataRow dr in MEMO.Rows)
                        {
                            try
                            {
                                String strSqldtXscWebSite = "SELECT * FROM MEMO";
                                strSqldtXscWebSite += " where ";
                                strSqldtXscWebSite += "  type='" + dr["type"] + "'";
                                strSqldtXscWebSite += "  AND TITLE='" + dr["TITLE"] + "'";
                                rs = ct.GetUpdateRs(strSqldtXscWebSite);
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["type"].Value = dr["type"];
                                    rs.Fields["OPTIME"].Value = dr["OPTIME"];
                                    rs.Fields["AddTime"].Value = dr["AddTime"];
                                    rs.Fields["OptUser"].Value = dr["OptUser"];
                                    rs.Fields["USERNAME"].Value = dr["USERNAME"];
                                    rs.Fields["TITLE"].Value = dr["TITLE"];
                                    rs.UpdateBatch(ADODB.AffectEnum.adAffectCurrent);
                                    lstStatus.Items.Add("备注表 增加了一条 日期为 " + ":" + dr["OPTIME"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }                                
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("备注表 更新 日期为 " + ":" + dr["OPTIME"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //MEMO

                        //ENGLISHMEMO
                       strSql = "select * from EnglishMEMO where  datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable EnglishMEMO = new DataTable();
                        sda.Fill(EnglishMEMO);
                        foreach (DataRow dr in EnglishMEMO.Rows)
                        {
                            try
                            {
                                String strSqldtXscWebSite = "SELECT * FROM EnglishMEMO";
                                strSqldtXscWebSite += " where ";
                                strSqldtXscWebSite += "  MemoID='" + dr["MemoID"] + "'";
                                strSqldtXscWebSite += "  AND EnglishWord='" + dr["EnglishWord"] + "'";
                                rs = ct.GetUpdateRs(strSqldtXscWebSite);
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["MemoID"].Value = dr["MemoID"];
                                    rs.Fields["EnglishWord"].Value = dr["EnglishWord"];
                                    rs.Fields["OPTIME"].Value = dr["OPTIME"];
                                    rs.UpdateBatch(ADODB.AffectEnum.adAffectCurrent);
                                    lstStatus.Items.Add("英语备注表 增加了一条 日期为 " + ":" + dr["OPTIME"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }                                
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); 
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("英语备注表 更新 日期为 " + ":" + dr["OPTIME"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //ENGLISHMEMO

                        //XSCSong
                        strSql = "select * from XSCSong where  datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable XSCSong = new DataTable();
                        sda.Fill(XSCSong);
                        foreach (DataRow dr in XSCSong.Rows)
                        {
                            try
                            {
                                String strSqldtXscWebSite = "SELECT * FROM XSCSong";
                                strSqldtXscWebSite += " where ";
                                strSqldtXscWebSite += "  Songer='" + dr["Songer"] + "'";
                                strSqldtXscWebSite += "  AND Song='" + dr["Song"] + "'";
                                rs = ct.GetUpdateRs(strSqldtXscWebSite);
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["Songer"].Value = dr["Songer"];
                                    rs.Fields["Song"].Value = dr["Song"];
                                    rs.Fields["OPTIME"].Value = dr["OPTIME"];
                                    rs.Fields["AddTime"].Value = dr["AddTime"];
                                    rs.Fields["OptUser"].Value = dr["OptUser"];
                                    rs.Fields["USERNAME"].Value = dr["USERNAME"];
                                    rs.UpdateBatch(ADODB.AffectEnum.adAffectCurrent);
                                    lstStatus.Items.Add("歌曲表 增加了一条 日期为 " + ":" + dr["OPTIME"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs);
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("歌曲表 更新 日期为 " + ":" + dr["OPTIME"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //XSCSong

                        //WysInput
                        strSql = "select * from WysInput where  datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable WysInput = new DataTable();
                        sda.Fill(WysInput);
                        foreach (DataRow dr in WysInput.Rows)
                        {
                            try
                            {
                                String strSqldtXscWebSite = "SELECT * FROM WysInput";
                                strSqldtXscWebSite += " where ";
                                strSqldtXscWebSite += "  ID='" + dr["ID"] + "'";
                                rs = ct.GetUpdateRs(strSqldtXscWebSite);
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["ID"].Value = dr["ID"];
                                    rs.Fields["Title"].Value = dr["Title"];
                                    rs.Fields["TYPE"].Value = dr["TYPE"];
                                    rs.Fields["Count"].Value = dr["Count"];
                                    rs.Fields["DateTime"].Value = dr["DateTime"];
                                    rs.Fields["OPTIME"].Value = dr["OPTIME"];
                                    rs.Fields["Memo"].Value = dr["Memo"];
                                    rs.UpdateBatch(ADODB.AffectEnum.adAffectCurrent);
                                    lstStatus.Items.Add("收入表 增加了一条 内容为 " + ":" + dr["Title"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                else
                                {
                                    rs.Fields["Title"].Value = dr["Title"];
                                    rs.Fields["TYPE"].Value = dr["TYPE"];
                                    rs.Fields["Count"].Value = dr["Count"];
                                    rs.Fields["DateTime"].Value = dr["DateTime"];
                                    rs.Fields["OPTIME"].Value = dr["OPTIME"];
                                    rs.Fields["Memo"].Value = dr["Memo"];
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value); 
                                    lstStatus.Items.Add("收入表 更新了一条 内容为 " + ":" + dr["Title"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs);
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("收入表 更新 内容为 " + ":" + dr["Title"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //WysInput

                        //WysOutput
                        strSql = "select * from WysOutput where  datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable WysOutput = new DataTable();
                        sda.Fill(WysOutput);
                        foreach (DataRow dr in WysOutput.Rows)
                        {
                            try
                            {
                                String strSqldtXscWebSite = "SELECT * FROM WysOutput";
                                strSqldtXscWebSite += " where ";
                                strSqldtXscWebSite += "  ID='" + dr["ID"] + "'";
                                rs = ct.GetUpdateRs(strSqldtXscWebSite);
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["ID"].Value = dr["ID"];
                                    rs.Fields["Title"].Value = dr["Title"];
                                    rs.Fields["TYPE"].Value = dr["TYPE"];
                                    rs.Fields["Count"].Value = dr["Count"];
                                    rs.Fields["DateTime"].Value = dr["DateTime"];
                                    rs.Fields["OPTIME"].Value = dr["OPTIME"];
                                    rs.Fields["Memo"].Value = dr["Memo"];
                                    rs.UpdateBatch(ADODB.AffectEnum.adAffectCurrent);
                                    lstStatus.Items.Add("收入表 增加了一条 内容为 " + ":" + dr["Title"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                else
                                {
                                    rs.Fields["Title"].Value = dr["Title"];
                                    rs.Fields["TYPE"].Value = dr["TYPE"];
                                    rs.Fields["Count"].Value = dr["Count"];
                                    rs.Fields["DateTime"].Value = dr["DateTime"];
                                    rs.Fields["OPTIME"].Value = dr["OPTIME"];
                                    rs.Fields["Memo"].Value = dr["Memo"];
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value); 
                                    lstStatus.Items.Add("收入表 更新了一条 内容为 " + ":" + dr["Title"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs);
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("收入表 更新 表名为 " + ":" + dr["Title"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //WysOutput

                        //CrashInOut
                        strSql = "select * from CrashInOut where  datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable CrashInOut = new DataTable();
                        sda.Fill(CrashInOut);
                        foreach (DataRow dr in CrashInOut.Rows)
                        {
                            try
                            {
                                String strSqldtXscWebSite = "SELECT * FROM CrashInOut";
                                strSqldtXscWebSite += " where ";
                                strSqldtXscWebSite += "  ID='" + dr["ID"] + "'";
                                rs = ct.GetUpdateRs(strSqldtXscWebSite);
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["ID"].Value = dr["ID"];
                                    rs.Fields["InOutID"].Value = dr["InOutID"];
                                    rs.Fields["CrashStatusID"].Value = dr["CrashStatusID"];
                                    rs.Fields["CrashStatusCount"].Value = dr["CrashStatusCount"];
                                    rs.Fields["OPTIME"].Value = dr["OPTIME"];                                    
                                    rs.Fields["TYPE"].Value = dr["TYPE"];
                                    rs.Fields["USERNAME"].Value = dr["USERNAME"];
                                    rs.Fields["MEMO"].Value = dr["MEMO"];
                                    rs.Fields["DATETIME"].Value = dr["DATETIME"];
                                    rs.Fields["LendId"].Value = dr["LendId"];
                                    rs.UpdateBatch(ADODB.AffectEnum.adAffectCurrent);
                                    lstStatus.Items.Add("CrashInOut表 增加了一条 编号为 " + ":" + dr["ID"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                else
                                {
                                    rs.Fields["InOutID"].Value = dr["InOutID"];
                                    rs.Fields["CrashStatusID"].Value = dr["CrashStatusID"];
                                    rs.Fields["CrashStatusCount"].Value = dr["CrashStatusCount"];
                                    rs.Fields["OPTIME"].Value = dr["OPTIME"];
                                    rs.Fields["TYPE"].Value = dr["TYPE"];
                                    rs.Fields["USERNAME"].Value = dr["USERNAME"];
                                    rs.Fields["MEMO"].Value = dr["MEMO"];
                                    rs.Fields["DATETIME"].Value = dr["DATETIME"];
                                    rs.Fields["LendId"].Value = dr["LendId"];
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value); 
                                    lstStatus.Items.Add("CrashInOut表 更新了一条 编号为 " + ":" + dr["ID"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs);
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("CrashInOut表 更新 编号为 " + ":" + dr["ID"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //CrashInOut

                        //CrashStatus
                        strSql = "select * from CrashStatus where  datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable CrashStatus = new DataTable();
                        sda.Fill(CrashStatus);
                        CrashStatus.TableName = "CrashStatus";
                        
                        keys.Clear();
                        insertParam.Clear();
                        UpdateParam.Clear();
                        SelectParam.Clear();
                        insertParam.Add(cmdTemp.CreateParameter("ID",
                                       ADODB.DataTypeEnum.adChar, ADODB.ParameterDirectionEnum.adParamInput,
                                       36,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("Title",
                                       ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput,
                                       50,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("Count",
                                       ADODB.DataTypeEnum.adDecimal, ADODB.ParameterDirectionEnum.adParamInput,
                                       0,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("MEMO",
                                       ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput,
                                       500,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("OPTIME",
                                       ADODB.DataTypeEnum.adDBTimeStamp, ADODB.ParameterDirectionEnum.adParamInput,
                                       100,
                                       System.Reflection.Missing.Value));
                        insertParam.Add(cmdTemp.CreateParameter("InitCount",
                                       ADODB.DataTypeEnum.adDecimal, ADODB.ParameterDirectionEnum.adParamInput,
                                       0,
                                       System.Reflection.Missing.Value));

                        SelectParam.Add(cmdTemp.CreateParameter("ID1",
                                       ADODB.DataTypeEnum.adChar, ADODB.ParameterDirectionEnum.adParamInput,
                                       36,
                                       System.Reflection.Missing.Value));

                        UpdateParam.AddRange(insertParam);
                        UpdateParam.AddRange(SelectParam);

                        keys.Add("ID");

                        更新表(CrashStatus, keys, insertParam.ToArray(), UpdateParam.ToArray(), SelectParam.ToArray());
                      
                        //WysBorrowLend
                        strSql = "select * from WysBorrowLend where  datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable WysBorrowLend = new DataTable();
                        sda.Fill(WysBorrowLend);
                        foreach (DataRow dr in WysBorrowLend.Rows)
                        {
                            try
                            {
                                String strSqldtXscWebSite = "SELECT * FROM WysBorrowLend";
                                strSqldtXscWebSite += " where ";
                                strSqldtXscWebSite += "  ID='" + dr["ID"] + "'";
                                rs = ct.GetUpdateRs(strSqldtXscWebSite);
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["ID"].Value = dr["ID"];
                                    rs.Fields["LendBorrowUserName"].Value = dr["LendBorrowUserName"];
                                    rs.Fields["Count"].Value = dr["Count"];
                                    rs.Fields["DateTime"].Value = dr["DateTime"];
                                    rs.Fields["OPTIME"].Value = dr["OPTIME"];
                                    rs.Fields["Memo"].Value = dr["Memo"];
                                    rs.Fields["UserName"].Value = dr["UserName"];
                                    rs.Fields["Status"].Value = dr["Status"];
                                    rs.Fields["Type"].Value = dr["Type"];
                                    rs.UpdateBatch(ADODB.AffectEnum.adAffectCurrent);
                                    lstStatus.Items.Add("借出借入表 增加了一条 编号为 " + ":" + dr["ID"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                else
                                {
                                    rs.Fields["LendBorrowUserName"].Value = dr["LendBorrowUserName"];
                                    rs.Fields["Count"].Value = dr["Count"];
                                    rs.Fields["DateTime"].Value = dr["DateTime"];
                                    rs.Fields["OPTIME"].Value = dr["OPTIME"];
                                    rs.Fields["Memo"].Value = dr["Memo"];
                                    rs.Fields["UserName"].Value = dr["UserName"];
                                    rs.Fields["Status"].Value = dr["Status"];
                                    rs.Fields["Type"].Value = dr["Type"];
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value); 
                                    lstStatus.Items.Add("借出借入表 更新了一条 编号为 " + ":" + dr["ID"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs);
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("借出借入表 更新 编号为 " + ":" + dr["ID"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //WysBorrowLend

                        //WysInputUser
                        strSql = "select * from WysInputUser where  datetime([OPTIME])>='" + txtVersion.Text + "'";
                        sda = new System.Data.SQLite.SQLiteDataAdapter(strSql, sc);
                        DataTable WysInputUser = new DataTable();
                        sda.Fill(WysInputUser);
                        foreach (DataRow dr in WysInputUser.Rows)
                        {
                            try
                            {
                                String strSqldtXscWebSite = "SELECT * FROM WysInputUser";
                                strSqldtXscWebSite += " where ";
                                strSqldtXscWebSite += "  ID='" + dr["ID"] + "'";
                                rs = ct.GetUpdateRs(strSqldtXscWebSite);
                                if (rs == null)
                                    continue;
                                if (rs.EOF)
                                {
                                    rs.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                                    rs.Fields["ID"].Value = dr["ID"];
                                    rs.Fields["UserName"].Value = dr["UserName"];
                                    rs.Fields["Memo"].Value = dr["Memo"];
                                    rs.Fields["OPTIME"].Value = dr["OPTIME"];
                                    rs.Fields["COLOR"].Value = dr["COLOR"];
                                    rs.Fields["TYPE"].Value = dr["TYPE"];
                                    rs.UpdateBatch(ADODB.AffectEnum.adAffectCurrent);
                                    lstStatus.Items.Add("账户表 增加了一条 名称为 " + ":" + dr["UserName"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                else
                                {
                                    rs.Fields["UserName"].Value = dr["UserName"];
                                    rs.Fields["Memo"].Value = dr["Memo"];
                                    rs.Fields["OPTIME"].Value = dr["OPTIME"];
                                    rs.Fields["COLOR"].Value = dr["COLOR"];
                                    rs.Fields["TYPE"].Value = dr["TYPE"];
                                    rs.Update(System.Reflection.Missing.Value, System.Reflection.Missing.Value); 
                                    lstStatus.Items.Add("用户表 更新了一条 名称为 " + ":" + dr["UserName"].ToString() + "的记录");
                                    System.Windows.Forms.Application.DoEvents(); //刷新界面
                                }
                                rs.Close();
                                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs);
                                rs = null;
                            }
                            catch (Exception me)
                            {
                                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                                lstStatus.Items.Add("用户表 更新 名称为 " + ":" + dr["UserName"].ToString() + "的记录 失败");
                                System.Windows.Forms.Application.DoEvents(); //刷新界面
                            }
                        }
                        //WysInputUser
                        sc.Close();
                    }
                    catch (Exception me)
                    {
                        UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());
                    }
                }           

            }

            //查找图片文件
            if (chkGroup3Image.Checked)
            {
                String strTargetImage = System.IO.Path.Combine(this.GetCurrentDirectory(), "Images");
                if (!System.IO.Directory.Exists(strTargetImage))
                {
                    System.IO.Directory.CreateDirectory(strTargetImage);
                }

                System.IO.FileInfo[] fifs = GetImages(strPathChild);

                if (fifs == null)
                {
                    goto Atts;
                }
                foreach (System.IO.FileInfo fin1 in fifs)
                {
                    try
                    {
                        fin1.CopyTo(System.IO.Path.Combine(strTargetImage, fin1.Name), true);
                        lstStatus.Items.Add("拷贝图片" + fin1.Name + "成功");
                        System.Windows.Forms.Application.DoEvents(); //刷新界面
                    }
                    catch (Exception)
                    {
                        lstStatus.Items.Add("拷贝图片" + fin1.Name + "失败");
                        System.Windows.Forms.Application.DoEvents(); //刷新界面
                    }
                }
            }
        Atts:
            //查找附件文件
            if (this.chkGroup3Att.Checked)
            {
                String strTargetImage = System.IO.Path.Combine(this.GetCurrentDirectory(), "UpLoad");
                if (!System.IO.Directory.Exists(strTargetImage))
                {
                    System.IO.Directory.CreateDirectory(strTargetImage);
                }

                System.IO.FileInfo[] fifs = GetAtts(strPathChild);

                if (fifs == null)
                {
                    goto SoftWare;
                }

                foreach (System.IO.FileInfo fin1 in fifs)
                {
                    try
                    {
                        fin1.CopyTo(System.IO.Path.Combine(strTargetImage, fin1.Name), true);
                        lstStatus.Items.Add("拷贝附件" + fin1.Name + "成功");
                        System.Windows.Forms.Application.DoEvents(); //刷新界面
                    }
                    catch (Exception)
                    {
                        lstStatus.Items.Add("拷贝附件" + fin1.Name + "失败");
                        System.Windows.Forms.Application.DoEvents(); //刷新界面
                    }
                }
            }
        SoftWare:
            //查找小软件
            if (chkSoftWare.Checked)
            {
                String strTargetImage = System.IO.Path.Combine(this.GetCurrentDirectory(), "SoftWare");
                if (!System.IO.Directory.Exists(strTargetImage))
                {
                    System.IO.Directory.CreateDirectory(strTargetImage);
                }

                System.IO.DirectoryInfo[] fifs = GetSoftWare(strPathChild);

                if (fifs == null)
                {
                    goto DelFolder;
                }

                foreach (System.IO.DirectoryInfo dfi123 in fifs)
                {
                    try
                    {
                        CopyDir(dfi123.FullName, strTargetImage + System.IO.Path.DirectorySeparatorChar + dfi123.Name);
                        lstStatus.Items.Add("拷贝小软件" + dfi123.Name + "成功");
                        System.Windows.Forms.Application.DoEvents(); //刷新界面
                    }
                    catch (Exception)
                    {
                        lstStatus.Items.Add("拷贝小软件" + dfi123.Name + "成功");
                        System.Windows.Forms.Application.DoEvents(); //刷新界面
                    }

                }
            }
        DelFolder:
            //删除压缩的文件夹
            try
            {
                lstStatus.Items.Add("开始删除临时压缩文件夹。。。。。。");
                System.Windows.Forms.Application.DoEvents(); //刷新界面
                System.IO.Directory.Delete(strPathChild, true);
                lstStatus.Items.Add("删除临时压缩文件成功夹");
                System.Windows.Forms.Application.DoEvents(); //刷新界面
            }
            catch (Exception)
            {
                lstStatus.Items.Add("删除临时压缩文件失败,请手动删除");
                System.Windows.Forms.Application.DoEvents(); //刷新界面
            }

            this.txtCompressionPath.Text = "";

            //增加还原更新数据库 A-2010-02-22
            if (ShowMessageResult("已经还原成功，是否修改数据库版本") == DialogResult.Yes)
            {
                DataBaseVersion dv = new DataBaseVersion();
                dv.ShowDialog(this);
                System.Windows.Forms.Application.DoEvents(); //刷新界面
            }
            //增加还原更新数据库 A-2010-02-22

        }
        #endregion

        #region 拷贝文件夹
        private void CopyDir(string srcPath, string aimPath)
        {
            try
            {
                // 检查目标目录是否以目录分割字符结束如果不是则添加之 
                if (aimPath[aimPath.Length - 1] != System.IO.Path.DirectorySeparatorChar)
                {
                    aimPath += System.IO.Path.DirectorySeparatorChar;
                }

                // 判断目标目录是否存在如果不存在则新建之 
                if (!System.IO.Directory.Exists(aimPath))
                {
                    System.IO.Directory.CreateDirectory(aimPath);
                }

                // 得到源目录的文件列表，该里面是包含文件以及目录路径的一个数组 
                // 如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法 
                // string[] fileList = Directory.GetFiles(srcPath); 
                string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);

                // 遍历所有的文件和目录 
                foreach (string file in fileList)
                {
                    // 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件 
                    if (System.IO.Directory.Exists(file))
                    {
                        CopyDir(file, aimPath + System.IO.Path.GetFileName(file));
                    }

                    // 否则直接Copy文件 
                    else
                    {
                        System.IO.File.Copy(file, aimPath + System.IO.Path.GetFileName(file), true);
                    }
                }
            }

            catch (Exception me)
            {
                UTIL.CException.SaveExcepiton(UTIL.ErrorType.Error, me, MethodBase.GetCurrentMethod().GetType());//A-2009-10-11 
            }
        }
        #endregion

        private void chkTime_CheckedChanged(object sender, EventArgs e)
        {
            if (chkTime.Checked)
            {
                myLabel1.Visible = true;
                this.txtVersion.Visible = true;
                lblCurrent.Visible = true;
                this.txtCurrent.Visible = true;
                this.txtCurrent.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                ADODB.Recordset rs = ct.GetTable("select * from XSCVersion");
                if (!rs.EOF)
                {
                    this.txtVersion.Text = DateTime.Parse(rs.Fields["DateTime"].Value.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                    rs.Close();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
                }
            }
            else
            {
                myLabel1.Visible = false;
                this.txtVersion.Visible = false;
                lblCurrent.Visible = false;
                this.txtCurrent.Visible = false;
            }
        }

        public bool CommonExist(String id)
        {
            bool ret = false;
            ADODB.Recordset rs = null;
            ADODB.Command cmd = new ADODB.Command();
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("SELECT ID,replace(UPPER(WORD),' ','') AS WORD1 FROM XSCENLISHWORD   WHERE USERNAME=? And WORD1=?");

            ADODB.Parameter pa = cmd.CreateParameter("USERNAME", ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, strName.Length, this.strName);
            cmd.Parameters.Append(pa);

            pa = cmd.CreateParameter("WORD1", ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, id.Trim().Length, id.Trim().ToUpper());
            cmd.Parameters.Append(pa);

            cmd.CommandText = sb.ToString();
            rs = ct.ExcCommandAsRs(cmd);

            if (rs != null)
            {
                if (!rs.EOF)
                {
                    ret = true;
                }
                rs.Close();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(rs); //20100531
            }

            return ret;

        }
        
        public bool 更新表(DataTable dtSource, 
                           List<String> KeyColumnIndex,
                           ADODB.Parameter[] insertPa,
                           ADODB.Parameter[] UpdatePa,
                           ADODB.Parameter[] AddPa)
        {
            System.Windows.Forms.Application.DoEvents();

            if (dtSource.Rows.Count == 0)
            {
                return true;
            }
            if (KeyColumnIndex.Count == 0)
            {
                return true;
            }
            String strInsertSql = "";
            String strUpdateSql = "";
            String strSelectSql = "";

            //插入SQL
            strInsertSql = "Insert Into " + dtSource.TableName;
            strInsertSql += " (";
            for (int i = 0; i < dtSource.Columns.Count; i++)
            {
                strInsertSql += dtSource.Columns[i].ColumnName+",";
            }
            if (strInsertSql.EndsWith(","))
            {
                strInsertSql = strInsertSql.Substring(0, strInsertSql.Length - 1);
            }
            strInsertSql += ") VALUES(";
            for (int i = 0; i < dtSource.Columns.Count ; i++)
            {
                strInsertSql += " ?,";
            }
            if (strInsertSql.EndsWith(","))
            {
                strInsertSql = strInsertSql.Substring(0, strInsertSql.Length - 1);
            }
            strInsertSql += ")";

            //更新SQL
            strUpdateSql = "Update " + dtSource.TableName + " Set ";
            for (int i = 0; i < dtSource.Columns.Count; i++)
            {
                strUpdateSql += dtSource.Columns[i].ColumnName + " = ?,";
            }
            if (strUpdateSql.EndsWith(","))
            {
                strUpdateSql = strUpdateSql.Substring(0, strUpdateSql.Length - 1);
            }
            strUpdateSql += " Where ";
            for (int i = 0; i < KeyColumnIndex.Count; i++)
            {
                strUpdateSql += KeyColumnIndex[i] + " = ? AND";
            }
            if (strUpdateSql.EndsWith(" AND"))
            {
                strUpdateSql = strUpdateSql.Substring(0, strUpdateSql.Length - 4);
            }

            //选择SQL
            strSelectSql = "Select * From " + dtSource.TableName;
            strSelectSql += " Where ";
            for (int i = 0; i < KeyColumnIndex.Count; i++)
            {
                strSelectSql += KeyColumnIndex[i]+ " = ? AND";
            }
            if (strSelectSql.EndsWith(" AND"))
            {
                strSelectSql = strSelectSql.Substring(0, strSelectSql.Length - 4);
            }

            ADODB.Command  cmdInsert=new ADODB.Command();
            cmdInsert.Prepared = true;
            cmdInsert.CommandText=strInsertSql;
            for(int idex=0;idex<=insertPa.Length-1;idex++)
            {
                cmdInsert.Parameters.Append(insertPa[idex]);
            }
            ct.ExcCommand(cmdInsert);

            ADODB.Command cmdUpdate=new ADODB.Command();
            cmdUpdate.CommandText = strUpdateSql;
            cmdUpdate.Prepared = true;
            for(int idex=0;idex<=UpdatePa.Length-1;idex++)
            {
                cmdUpdate.Parameters.Append(UpdatePa[idex]);
            }
            ct.ExcCommand(cmdUpdate);

            ADODB.Command cmdSelect=new ADODB.Command();
            cmdSelect.CommandText = strSelectSql;
            cmdSelect.Prepared = true;
            for(int idex=0;idex<=AddPa.Length-1;idex++)
            {
                cmdSelect.Parameters.Append(AddPa[idex]);
            }
            ct.ExcCommand(cmdSelect);

            for (int idex = 0; idex < dtSource.Rows.Count; idex++)
            {
                try
                {
                    //查询数据库 如果存在的话
                    //添加
                    for (int jdex = 0; jdex < KeyColumnIndex.Count; jdex++)
                    {
                        cmdSelect.Parameters[jdex].Value = dtSource.Rows[idex][KeyColumnIndex[jdex]];
                    }
                    ADODB.Recordset rs = ct.ExcCommandAsRs(cmdSelect);
                    bool BInsert = false;
                    if (rs == null)
                    {
                        BInsert = true;
                    }
                    else
                    {
                        if (rs.EOF)
                        {
                            BInsert = true;
                        }
                        else
                        {
                            BInsert = false;
                        }
                        rs.Close();
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(rs);
                    }
                    if (BInsert)
                    {                       
                        for (int jdex = 0; jdex < dtSource.Columns.Count; jdex++)
                        {
                            cmdInsert.Parameters[jdex].Value = dtSource.Rows[idex][jdex];
                        }
                        if (ct.ExcCommand(cmdInsert))
                        {
                            添加状态(BInsert, true, dtSource.Rows[idex], KeyColumnIndex);
                        }
                        else
                        {
                            添加状态(BInsert, false, dtSource.Rows[idex], KeyColumnIndex);
                        }
                    }
                    else
                    {
                        //更新
                        for (int jdex = 0; jdex < dtSource.Columns.Count; jdex++)
                        {
                            cmdUpdate.Parameters[jdex].Value = dtSource.Rows[idex][jdex];
                        }
                        for (int jdex = 0; jdex < KeyColumnIndex.Count; jdex++)
                        {
                            cmdUpdate.Parameters[dtSource.Columns.Count  + jdex].Value = dtSource.Rows[idex][KeyColumnIndex[jdex]];
                        }
                        if (ct.ExcCommand(cmdUpdate))
                        {
                            添加状态(BInsert, true, dtSource.Rows[idex], KeyColumnIndex);
                        }
                        else
                        {
                            添加状态(BInsert, false, dtSource.Rows[idex], KeyColumnIndex);
                        }
                        
                    }
                   
                }
                catch (Exception )
                {
                    lstStatus.Items.Add(dtSource.TableName + "表 失败了一条记录");
                }
                
                             
            }
            return true;
        }

        public void 添加状态(bool BInsert ,bool bError,DataRow dr, List<String> KeyColumnIndex)
        {
            String strContent = "";
            strContent = dr.Table.TableName + "表 ";
            if (BInsert)
            {

                if (bError)
                {
                    strContent +="成功 ";
                }
                else
                {
                    strContent +="失败 ";
                }
                 strContent +="添加 ";
            }
            else
            {
                if (bError)
                {
                    strContent +="成功 ";
                }
                else
                {
                    strContent +="失败 ";
                }
                strContent +=" 更新 ";
            }
            strContent +="主键为 ";
            for (int idex = 0; idex<=KeyColumnIndex.Count - 1; idex++)
            {
                strContent += dr[KeyColumnIndex[idex]].ToString();
            }
            strContent += "的记录";
            lstStatus.Items.Add(strContent);
        }
    }

  
}
